package com.javasm.controller.goodsController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.javasm.common.http.AxiosResult;
import com.javasm.common.page.PageResult;
import com.javasm.common.perm.HasPerm;
import com.javasm.controller.base.BaseController;
import com.javasm.domin.criteria.goodsCriteria.GdBrandCriteria;
import com.javasm.domin.entity.goodsEntity.GdBrand;
import com.javasm.domin.vo.goodsVo.GdBrandVo;
import com.javasm.mapper.goodsMapper.GdBrandMapper;
import com.javasm.service.goodsService.GdBrandService;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：zzt
 * @Version：1.0
 * @Date：2021/11/19-10:35
 * @Since:jdk1.8
 * @Description:
 */
@RestController
@RequestMapping("/brand")
@RequiredArgsConstructor
public class GdBrandController extends BaseController {


    private final GdBrandService gdBrandService;


    /**
     * 查所有
     * @param
     * @return
     */
    @GetMapping("list")
    public AxiosResult<List<GdBrand>> list(){

        List<GdBrand> list = gdBrandService.list();
//        System.out.println(list.toString());
        return AxiosResult.success(list);
    }


    /**
     * 分页查所有
     * @param gdBrandCriteria
     * @return
     */
    @GetMapping("findByCriteria")
    public AxiosResult<PageResult<GdBrandVo>> findByCriteria(GdBrandCriteria gdBrandCriteria){


        PageResult<GdBrandVo> gdBrandVoPageResult = gdBrandService.selectCriteria(gdBrandCriteria);


        return AxiosResult.success(gdBrandVoPageResult);
    }


    @PostMapping("addBrand")
    public AxiosResult addBrand(@RequestBody GdBrand gdBrand){

        return AxiosResult.success(gdBrandService.save(gdBrand));

    }


    @PutMapping("updateBrand")
    public AxiosResult updateBrand(@RequestBody GdBrand gdBrand){

        return AxiosResult.success(gdBrandService.updateById(gdBrand));

    }

    @DeleteMapping("deleteById/{id}")
    public AxiosResult deleteById(@PathVariable Long id){

        int i = gdBrandService.selectBrandId(id);

        if (i>0){
            return AxiosResult.success(gdBrandService.removeById(800000000));
        }else {
            return AxiosResult.success(gdBrandService.removeById(id));
        }



    }

    @DeleteMapping("batchDelete/{ids}")
    public AxiosResult batchDelete(@PathVariable List<Long> ids){

        int i = gdBrandService.batchDeleteByIds(ids);

        if (i>0){
            return toAxios(10);
        }else {
            return toAxios(gdBrandService.batchDeleteByIds(ids));
        }


    }



}
